# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

#source 'https://github.com/CocoaPods/Specs.git'
#source 'http://HAERBINBANK:hrbb9999@101.52.126.173:8089/upsdk_release/upsdkpodspecs.git'
#ENV["UPSDK_URL"] = "http://HAERBINBANK:hrbb9999@101.52.126.173:8089/upsdk_release"

target 'myWeiKuaidi' do
  
#  use_frameworks!
  pod 'XcodeCoverage', '1.4'
#  pod 'Coverage'
#  pod 'HDCoverage'
end

#针对pods管理第三方的库开启覆盖率分析
ntargets = Array['AFNetworking']
require 'xcodeproj'
require 'pathname'
#hook方法,可以再post_install添加一些处理脚本
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if ((config.name <=> 'Debug') == 0)
        ntargets.each do |ntarget|
          if(ntarget <=> target.name) == 0
            config.build_settings['GCC_GENERATE_TEST_COVERAGE_FILES'] = 'YES'
            config.build_settings['GCC_INSTRUMENT_PROGRAM_FLOW_ARCS'] = 'YES'
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) UP_CODECOVERAGE=1'
# 设置预编译变量CODECOVERAGE
#config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) CODECOVERAGE=1'
## OC代码覆盖率插桩配置
#config.build_settings['OTHER_CFLAGS'] = '$(inherited) -fprofile-instr-generate -fcoverage-mapping'
## Swift代码覆盖率插桩配置
#config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -profile-generate -profile-coverage-mapping'
## 采集代码覆盖率配置
#config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -fprofile-instr-generate'
## Release需要设置，不然无法解析代码覆盖率
#config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
            break
          end
        end
      end
    end
  end
end

#针对主工程target开启覆盖率分析
project_path = Dir.pwd + '/myWeiKuaidi.xcodeproj'
project = Xcodeproj::Project.open(project_path)
project.targets.each do |target|
  if (target.name <=> 'myWeiKuaidi') == 0
    target.build_configurations.each do |config|
      if (config.name <=> 'Debug') == 0
        # OC代码覆盖率插桩配置
        config.build_settings['GCC_GENERATE_TEST_COVERAGE_FILES'] = 'YES'
        config.build_settings['GCC_INSTRUMENT_PROGRAM_FLOW_ARCS'] = 'YES'
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) UP_CODECOVERAGE=1'
# 设置预编译变量CODECOVERAGE
#config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) CODECOVERAGE=1'
## OC代码覆盖率插桩配置
#config.build_settings['OTHER_CFLAGS'] = '$(inherited) -fprofile-instr-generate -fcoverage-mapping'
## Swift代码覆盖率插桩配置
#config.build_settings['OTHER_SWIFT_FLAGS'] = '$(inherited) -profile-generate -profile-coverage-mapping'
## 采集代码覆盖率配置
#config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -fprofile-instr-generate'
## Release需要设置，不然无法解析代码覆盖率
#config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
      end
    end
  end
  project.save()
end
